<script>
    function get(url, params, headersFn = null) {
        return new Promise((resolve, reject) => {
            const xhr = new XMLHttpRequest
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    let res = JSON.parse(xhr.responseText)
                    resolve(res)
                } else {
                    reject(xhr.status)
                }
            }
            xhr.open('get', `${url}?${params}`)
            if (headersFn) headersFn(xhr)
            xhr.send(null)
        })
    }
</script>
<script>
function post(url, params, headersFn = null) {
        return new Promise((resolve, reject) => {
            const xhr = new XMLHttpRequest
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    let res = JSON.parse(xhr.responseText)
                    resolve(res)
                } else {
                    reject(xhr.status)
                }
            }
            xhr.open('get', `${url}?${params}`)
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded')
            if (headersFn) headersFn(xhr)
            xhr.send(params)
        })
    }
</script>